#ifndef __SINGLETON_H__
#define __SINGLETON_H__

namespace util
{
    template <typename Type>
    class Singleton
    {
    public:
        static Type* instance()
        {
            if (Singleton<Type>::_instance == nullptr)
                Singleton<Type>::_instance = new Type();
            return Singleton<Type>::_instance;
        }

        static void free()
        {
            delete Singleton<Type>::_instance;
            Singleton<Type>::_instance = nullptr;
        }

    private:
        Singleton() {}
        Singleton(const Singleton<Type>& );
        Singleton(Singleton<Type>&& );
        Singleton<Type>& operator = (const Singleton<Type> &);
        Singleton<Type>& operator = (Singleton<Type>&&);
        ~Singleton() {}

    private:
        static Type* _instance;
    };

    template <typename Type>
    Type* Singleton<Type>::_instance = nullptr;
}

#endif